<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <title>无标题文档</title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css"/>
    <link href="../../css/select.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../js/jquery.js"></script>
    <script type="text/javascript" src="../../js/jquery.idTabs.min.js"></script>
    <script type="text/javascript" src="../../js/select-ui.min.js"></script>
    <script type="text/javascript" src="../../js/laydate/laydate.js"></script>
    <script type="text/javascript">
        KE.show({
            id: 'content7',
            cssPath: './index.css'
        });
    </script>
    <script type="text/javascript">


        $(document).ready(function (e) {
            $(".select1").uedSelect({
                width: 345
            });
            $(".select2").uedSelect({
                width: 167
            });
            $(".select3").uedSelect({
                width: 100
            });


        });


    </script>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">员工信息管理</a></li>
        <li><a href="#">添加员工信息</a></li>
    </ul>
</div>
<div class="formbody">
    <div class="formtitle"><span>员工修改</span></div>
    <form id="form1" name="form1" method="post">
        <div id="usual1" class="usual">
            <div id="tab1" class="tabson">
                <ul class="forminfo">
                    <li>
                        <label>员工账号<b>*</b></label>
                        <div class="vocation">
                            <input name="account" type="text" onblur="checkaccount()" id="account" class="dfinput"
                                   value="" style="width:344px;"/>

                        </div>
                        <span id="acc"></span>
                    </li>
                    <br/>
                    <li style="margin-top:20px;">
                        <label for="name">员工自编号<b>*</b></label>
                        <div class="vocation">
                            <input name="id" type="text" class="dfinput" disabled="disabled" value="" id="id"
                                   style="width:344px;"/>
                        </div>
                    </li>
                    <br/>
                    <li style="margin-top:20px;">
                        <label for="name">员工真实姓名<b>*</b></label>
                        <div class="vocation">
                            <input name="realname" type="text" class="dfinput" value="" style="width:344px;"/>
                        </div>
                    </li>
                    <br/>
                    <li style="margin-top:20px;">
                        <label for="name">员工登陆密码<b>*</b></label>
                        <div class="vocation">
                            <input name="password" type="text" id="upwd" class="dfinput" onblur="checkpassword()"
                                   value="" style="width:344px;"/>
                        </div>
                        <span id="pd"></span>
                    </li>
                    <br/>
                    <li style="margin-top:20px;">
                        <label for="sex">性别<b>*</b></label>
                        <input name="sex" type="radio" value="男" style="margin-top:10px;">男&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="sex" type="radio" value="女" style="margin-top:10px;">女
                    </li>
                    <br/>
                    <li style="margin-top:10px;">
                        <label for="name">员工出生日期<b>*</b></label>
                        <div class="vocation">
                            <input name="birthdate" type="text" class="dfinput" id="birthDate" value=""
                                   disabled="disabled"
                                   style="width:344px;"/>
                        </div>
                    </li>
                    <br/>

                    <li>
                        <label for="name">员工身份证号<b>*</b></label>
                        <div class="vocation">
                            <input name="idcard" type="text" class="dfinput" id="idCard" value="" disabled="disabled"
                                   style="width:344px;"/>
                        </div>
                    </li>
                    <br/>
                    <li>
                        <label for="name">员工手机号码<b>*</b></label>
                        <div class="vocation">
                            <input name="phone" type="text" id="tel" class="dfinput" value="" style="width:344px;"/>
                        </div>
                        <span id="phone"></span>
                    </li>
                    <br/>
                    <li>
                        <label for="name">员工地址<b>*</b></label>
                        <div class="vocation">
                            <input name="address" type="text" class="dfinput" value="" style="width:344px;"/>
                        </div>
                    </li>
                    <br/>
                    <li>
                        <label for="name">员工类型<b>*</b></label>
                        <div class="vocation">
                            <!--   <input name="" type="text" class="dfinput" value="请填写单位名称"  style="width:518px;"/>-->
                            <select class="select1" name="type" value="">
                                <option value="1">经理</option>
                                <option value="2">员工</option>
                                <option>其他</option>
                            </select>
                        </div>
                    </li>
                    <br/>

                    <br/>
                    <li>
                        <label>&nbsp;</label>
                        <input name="" onclick="up()" type="button" class="btn" value="修改员工"/>
                    </li>
                </ul>
            </div>
        </div>
    </form>
    <script>
        window.onload = function () {
            document.getElementById('id').value = localStorage.getItem('id');
            document.getElementById('birthDate').value = localStorage.getItem('birthDate');
            document.getElementById('idCard').value = localStorage.getItem('idCard');
        }
    </script>

    <script>
        //判断手机号
        $("#tel").blur(function () {
            $(this).css("background-color", "#FFF")
            var text = $(this).val();
            var phone = /^[1]{1}\d{10}$/;
            if (phone.test(text) == false) {
                $("#phone").html("输入有误").css("color", "red");
                return false;
            } else {
                $("#phone").html("");
                return true;
            }
        });

        //判断登陆密码
        function checkpassword() {
            var text = $("#upwd").val();
            var phone = /^\d{6,10}$/;
            if (phone.test(text) == false) {
                $("#pd").html("输入有误").css("color", "red");
                return false;
            } else {
                $("#pd").html("");
                return true;
            }
        }

        function checkaccount() {
            //var flag=false;
            var bool = false;
            var text = $("#account").val();
            if (text == "") {
                $("#acc").text("请填写账户名称").css("color", "red");
                return false;
            } else {
                $.ajaxSettings.async = false;
                $.post("../../emplyee/checkaccount", {"account": text},
                    function (data, status) {
                        if (data.state == 1) {
                            $("#acc").text("该账号已存在").css("color", "red");
                            bool = false;
                        } else {
                            alert("账号可用");
                            $("#acc").text("账号可用").css("color", "green");
                            bool = true;
                        }
                    });

            }
            $.ajaxSettings.async = true;
            return bool;
        }

        function up() {
            alert("进入up");
            var id = $("#id").val();
            var account = $("input[name='account']").val();
            var realName = $("input[name='realname']").val();
            var password = $("input[name='password']").val();
            var sex = $("input[type='radio']:checked").val();
            var phone = $("input[name='phone']").val();
            var address = $("input[name='address']").val();
            var type = $("select option:checked").val();
          // alert(account + realName + password + sex + phone + address + type + id);
            if (checkpassword() && checkaccount()) {
                $.ajax({
                    url: "../../emplyee/up",
                    type: "POST",
                    data: {
                        id: id,
                        account: account,
                        realName: realName,
                        password: password,
                        sex: sex,
                        phone: phone,
                        address: address,
                        type: type
                    },
                    success: function (data, status) {
                        if (status == "success") {
                            console.log('请求成功');
                            console.log(data);
                            if (data.state == 0) {
                                window.location = "../emplyee/emplyeeinfo.html";
                            } else {
                                alert("修改失败")
                            }

                        }
                    },
                    error: function () {
                        console.log('请求失败');
                    }
                })
            } else {
                alert(checkaccount());
                alert(checkpassword());
                alert("信息不完整，请将信息填写完整！");
                return false;

            }
        }

    </script>
    <script type="text/javascript">

        $("#usual1 ul").idTabs();
    </script>
    <script type="text/javascript">
        $('.tablelist tbody tr:odd').addClass('odd');

        !function () {
            laydate.skin('qianhuang');
            laydate({elem: '#Calendar'});
            laydate.skin('qianhuang');
            laydate({elem: '#Calendar2'});
        }();
        $(function dd() {
            var d = new Date(), str = "";
            str += (d.getFullYear() + "-");
            str += "0";
            str += (d.getMonth() + 1 + "-");
            str += d.getDate();
            $("#Calendar").attr("value", str);
            $("#Calendar2").attr("value", str);
        });

    </script>
</div>
</body>
</html>
